Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-stringify

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-stringify

Stringify an object so it can be safely inlined in JavaScript code

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4M
decreased by-0.92%
Maintainers
1
Weekly downloads
 
Created

What is js-stringify?

The js-stringify npm package is used to safely serialize JavaScript values to JSON strings. It ensures that the output is a valid JavaScript string literal, which can be useful for embedding data in HTML or JavaScript code.

What are js-stringify's main functionalities?

Basic Stringify

This feature allows you to convert a JavaScript object into a JSON string. The output is a valid JavaScript string literal.

const stringify = require('js-stringify');
const obj = { key: 'value' };
const str = stringify(obj);
console.log(str); // Output: '{"key":"value"}'

Stringify with Special Characters

This feature ensures that special characters within the string are properly escaped, making the output safe for embedding in JavaScript code.

const stringify = require('js-stringify');
const obj = { key: 'value with special characters: \n \t' };
const str = stringify(obj);
console.log(str); // Output: '{"key":"value with special characters: \n \t"}'

Stringify Arrays

This feature allows you to convert arrays into JSON strings, ensuring that all elements are properly serialized.

const stringify = require('js-stringify');
const arr = [1, 'two', { three: 3 }];
const str = stringify(arr);
console.log(str); // Output: '[1,"two",{"three":3}]'

Other packages similar to js-stringify

FAQs

Package last updated on 28 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc